﻿using CompanyRatings.PerfTest.Models.Query;
using CompanyRatings.SQL.PerfTest.ConsoleApp.Repositories;
using CompanyRatings.SQL.PerfTest.ConsoleApp.Tests;
using PerfTestLib.Result;
using PerfTestLib.Runtime;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PerfTestLib.Utility;
using CompanyRatings.SQL.PerfTest.ConsoleApp.TestData;

namespace CompanyRatings.SQL.PerfTest.ConsoleApp.Tests
{
    public class CrDiskAndMemTest : CrTestBase
    {
        public CrDiskAndMemTest()
            : base(TestDataType.Cr_DiskAndMem)
        {

        }

        protected override object ProcessTestData(TestSpecIterationInstance<CrQuery> testIteration)
        {
            // create company ratings repo
            DSRDWMemRepository repo = new DSRDWMemRepository();

            // create query
            string query = testIteration.Data.ToXml();

            // get company ratings
            DataTable table = repo.GetCompanyRatings_DiskAndMem(query);

            // write data table to CSV (once)
            if (testIteration.RepeatIndex == 1 && testIteration.Iteration.MaxParallelism == 1)
            {
                table.WriteCsv(this.TestDataType.ToString(), testIteration.Iteration.Id, 0);
            }

            return new { Count = table.Rows.Count };
        }
    }
}
